package com.birdy.redis.action;

import com.birdy.dto.Response;
import com.birdy.redis.RedisFactory;
import io.lettuce.core.api.reactive.RedisReactiveCommands;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

import java.util.ArrayList;

/**
 * @author birdy
 * @date 2022/4/10 7:22 PM
 */
@RestController
@RequestMapping("/redis")
public class RedisAction {
    /**
     * redis测试方法
     */
    @RequestMapping("/test")
    public Response test() {
        RedisReactiveCommands<String, String> redisCommand = RedisFactory.getRedisCommand();
        ArrayList<Object> resList = new ArrayList<>();
        Flux.just("key1", "key2", "key3").flatMap(key -> redisCommand.set(key, "hello"))
                .subscribe(resList::add);
        return Response.builder().res(Response.SUCCESS).data("add_res", resList).build();
    }
}
